import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:jpush_flutter/jpush_flutter.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  //初始化极光推送
  @override
  void initState() {
    String reRegistrationID = '';
    super.initState();
    //创建JPush
    JPush jPush = JPush();
    //配置应用key
    jPush.setup(
        //Appkey唯一，开发着服务中
        appKey: '752e4e4481b1d4466e66879c',
        production: false,
        channel: "theChannel",
        //是否打印debug日志
        debug: true);
    jPush.getRegistrationID().then((value) => print(value));//打印registrationID
    //查询id适合点对点发送。
    jPush.setAlias('MrLuo'); //设置别名，适用于产品升级。
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('极光推送'),
      ),
      body: Center(),
    );
  }
}
